<template>
  <div id="youngStarting">
    <section class="startingbox" style="margin-top:10px">
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" border
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        >
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column type="selection" width="45" fixed>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" show-overflow-tooltip>
        </el-table-column>
        <!-- <el-table-column prop="state" label="状态" width="150" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{stataText(scope.row.state)}}
          </template>
        </el-table-column> -->
      </el-table>
    </section>
    <el-button type="success" style="margin-top:10px;" @click="startingSubmit" :loading="myloading">启动</el-button>
  </div>
</template>

<script>
export default {
  props: ['timestamp'],
  watch: {
    timestamp () {
      this.getList()
    }
  },
  data () {
    return {
      listLoading: false,
      ids: [],
      list: [
      ],
      pageNum: 1,
      pageSize: 20,
      totalnum: 10,
      Isace: 'asc',
      Sortkey: '',
      myloading: false
    }
  },
  methods: {
    stataText (id) {
      switch (id) {
        case 0:
          return '填报'
        case 1:
          return '初审'
        case 2:
          return '审查'
        case 3:
          return '完成'
      }
    },
    handleSelectionChange (val) {
      this.ids = val.map(item => item.id)
    },
    startingSubmit () {
      this.$confirm('确认启动吗?', '提示', {
        type: 'success'
      }).then(() => {
        let ids = this.ids
        if (ids.length > 0) {
          console.log(ids)
          console.log(this.ids)
          let para = {unitIds: ids}
          this.$http.post(this.$http.defaults.youngAPI + `api/busUnit/reset`, para).then(response => {
            if (response.data.success === true) {
              this.$message({
                message: '启动成功',
                type: 'success'
              })
              this.$emit('dialogHide')
            } else {
              console.log('启动失败:' + response.data.message)
              this.$message({
                message: '启动失败:' + response.data.message,
                type: 'error'
              })
            }
            this.getList()
          })
        } else {
          this.$message({
            message: '请至少选择一条信息',
            type: 'danger'
          })
        }
      }).catch(() => {
      })
    },
    getList () {
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .get(this.$http.defaults.youngAPI + `api/busUnit/getAvailableUnits`)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    }
  },
  mounted () {
    this.getList()
  }

}
</script>
<style>
#youngDeptList .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .startingbox .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .startingbox .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #youngDeptList .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #youngDeptList .el-button{
    color:#fff !important;
  }
  #youngDeptList h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #youngDeptList .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    padding:0;
  }
  .startingbox{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    overflow: hidden;
  }
</style>
